package com.cgi.ndk.wf.scan;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.ExposesResourceFor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author brizat
 */
@RestController
@ExposesResourceFor(Scan.class)
@RequestMapping("/scans")
public class ScanController {

    @Autowired
    private ScanRepository scanRepository;
    
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<Scan> save(@RequestBody Scan scan){
        return new ResponseEntity<>(scanRepository.save(scan), HttpStatus.CREATED);
    }
    
    @RequestMapping
    public ResponseEntity<List<Scan>> scans() {
        return new ResponseEntity<>(scanRepository.findAll(), HttpStatus.OK);
    }

    @RequestMapping("/{id}")
    public ResponseEntity<Scan> scan(@PathVariable("id") String id) {
        return new ResponseEntity<>(scanRepository.findOne(id), HttpStatus.OK);
    }
    
    /*@RequestMapping("search")
    public ResponseEntity<List<Scan>> scansByPackage(@RequestParam(value = "package", required = true)String pack) {
        return new ResponseEntity<>(scanRepository.findAll(), HttpStatus.OK);
    }*/

}
